import instance from "../../request";

export async function getAttractionInfo(id){
    try {
        const res = await instance({
            url: `/Attraction/${id}`,
            method: 'get',
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function getAttractionByRegion(regionId,pageNumber,pageSize){
    try {
        const res = await instance({
            url: `/Attraction/region/${regionId}`,
            method: 'get',
            params: {
                pageNumber: pageNumber,
                pageSize: pageSize
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function searchAttraction(pageNumber,pageSize,query){
    try {
        const res = await instance({
            url: '/Attraction/search',
            method: 'get',
            params: {
                pageNumber: pageNumber,
                pageSize: pageSize,
                query: query
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function getAttractionByRating(pageNumber,pageSize){
    try {
        const res = await instance({
            url: '/Attraction/rating',
            method: 'get',
            params: {
                pageNumber: pageNumber,
                pageSize: pageSize,
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function getAttractionBySelectCount(pageNumber,pageSize){
    try {
        const res = await instance({
            url: '/Attraction/selectCount',
            method: 'get',
            params: {
                pageNumber: pageNumber,
                pageSize: pageSize,
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function getAttractionByDistance(pageNumber,pageSize,latitude,longitude){
    try {
        const res = await instance({
            url: '/Attraction/distance',
            method: 'get',
            params: {
                pageNumber: pageNumber,
                pageSize: pageSize,
                latitude: latitude,
                longitude: longitude
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function likeAttraction(userId, attractionId){
    try {
        const res = await instance({
            url: '/Attraction/distance',
            method: 'get',
            params: {
                userId: userId,
                attractionId: attractionId
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function createAttractionComment(comment){
    try {
        const res = await instance({
            url: '/Attraction/createComment',
            method: 'get',
            data: comment
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}


export async function deleteAttractionComment(commentId){
    try {
        const res = await instance({
            url: '/Attraction/deleteComment',
            method: 'get',
            params: {
                commentId: commentId
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function getAttractionComments(attractionId, pageNumber, pageSize){
    try {
        const res = await instance({
            url: '/Attraction/getComments',
            method: 'get',
            params: {
                attractionId: attractionId,
                pageNumber: pageNumber,
                pageSize: pageSize
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function uploadCommentImage(userId, file){
    try {
        const res = await instance({
            url: '/Attraction/uploadCommentImage',
            method: 'post',
            params: {
                userId: userId
            },
            data: file
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function deleteCommentImage(imageUrl){
    try {
        const res = await instance({
            url: '/Attraction/deleteCommentImage',
            method: 'delete',
            params: {
                imageUrl: imageUrl
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function likeComment(userId, commentId){
    try {
        const res = await instance({
            url: '/Attraction/likeComment',
            method: 'get',
            params: {
                userId: userId,
                commentId: commentId
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}